#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.demo.module.user.controller;

import ${package}.auth.YkAuthUserDemoClient;
import ${package}.common.bean.po.JwtDetails;
import ${package}.common.bean.po.User;
import ${package}.common.bean.vo.JsonResult;
import ${package}.common.bean.vo.LoginVo;
import ${package}.common.emum.ReturnCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description: 用户模块openfeign调用demo
 *
 * @author songcx
 * @date 2019/8/20 14:10
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@RestController
@Slf4j
@AllArgsConstructor
@RequestMapping("/demo/user/")
@Api(description = "用户模块feign调用demo")
public class UserController {

    /**
     * feign调用用户模块客户端
     */
    YkAuthUserDemoClient ykAuthUserDemoClient;

    /**
     * Description:
     * <openfeign调用get请求demo>
     *
     * @author songcx
     * @date 14:24 2019/8/20
     **/
    @GetMapping("/")
    @ApiOperation(value = "获取所有用户", notes = "获取所有用户")
    public JsonResult<List<User>> findAllUser() {
        List<User> userList;
        userList = ykAuthUserDemoClient.findAllUser();
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, userList);
//        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS);
    }

    /**
     * Description:
     * <openfeign调用post请求传递实体类demo>
     *
     * @param loginVo 1
     * @return JsonResult<JwtDetails>
     * @author songcx
     * @date 9:48 2019/8/21
     **/
    @PostMapping("/")
    @ApiOperation(value = "使用账户名和密码登录", notes = "使用账户名和密码登录")
    @ApiImplicitParam(name = "loginVo", value = "登录实体类", dataType = "LoginVo", paramType = "body", required = true)
    public JsonResult<JwtDetails> loginByUserId(@RequestBody LoginVo loginVo) {
        return ykAuthUserDemoClient.loginByUserId(loginVo);
    }

    /**
     * Description:
     * <openfeign调用delete请求demo>
     *
     * @param id 1
     * @return JsonResult
     * @author songcx
     * @date 10:01 2019/8/21
     **/
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除用户", notes = "根据id删除用户")
    @ApiImplicitParam(name = "id", value = "用户id", dataType = "Long", paramType = "path", required = true)
    public JsonResult deleteUser(@PathVariable Long id) {
        return ykAuthUserDemoClient.deleteUser(id);
    }

    /**
     * Description:
     * <openfeign调用get请求传递基本类型参数demo>
     *
     * @param id 1
     * @return JsonResult<User>
     * @author songcx
     * @date 10:06 2019/8/21
     **/
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询用户信息", notes = "根据id查询用户信息")
    @ApiImplicitParam(name = "id", value = "用户id", dataType = "Long", paramType = "path", required = true)
    public JsonResult<User> queryUserById(@PathVariable Long id) {
        return ykAuthUserDemoClient.queryUserById(id);
    }

    @GetMapping("/{username}/{id}")
    @ApiOperation(value = "查询账户是否存在", notes = "查询账户是否存在")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名称", dataType = "String", paramType = "path", required = true),
            @ApiImplicitParam(name = "id", value = "用户id", dataType = "Long", paramType = "path", required = true)
    })
    public JsonResult<Boolean> userVerifyUserId(@PathVariable("username") String username, @PathVariable("id") Long id) {
        return ykAuthUserDemoClient.userVerifyUserId(username, id);
    }
}
